<?php


namespace app\api\lists;


use app\common\model\goods\GoodsCategory;

class GoodsCategoryLists extends BaseShopDataLists
{
    /**
     * @notes 服务分类列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/2/18 10:55 上午
     */
    public function lists(): array
    {
        $lists = (new GoodsCategory())->field('id,pid,name,level,image')
            ->order(['sort'=>'desc','id'=>'asc'])
            ->select()
            ->toArray();

        $lists = linear_to_tree($lists,'sons');
        return $lists;
    }

    /**
     * @notes 服务分类总数
     * @return int
     * @author ljj
     * @date 2022/2/18 10:55 上午
     */
    public function count(): int
    {
        return (new GoodsCategory())->count();
    }
}